<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文本生成视频</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .container-excel {
            background-color: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-top: 20px;
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            width: 100%;
        }
        button:hover {
            background-color: #0056b3;
        }
        .flash-messages {
            margin-bottom: 20px;
        }
        .flash-success {
            background-color: #d4edda;
            color: #155724;
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #c3e6cb;
        }
        .flash-error {
            background-color: #f8d7da;
            color: #721c24;
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #f5c6cb;
        }
        .navigation {
            margin-top: 30px;
            text-align: center;
        }
        .nav-link {
            display: inline-block;
            margin: 10px;
            color: #007bff;
            text-decoration: none;
            padding: 10px 20px;
            border: 1px solid #007bff;
            border-radius: 5px;
        }
        .nav-link:hover {
            background-color: #007bff;
            color: white;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            border-radius: 5px;
            display: none;
        }
        .success {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }
        .error {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        .note {
            background-color: #fff3cd;
            border: 1px solid #ffeaa7;
            border-radius: 5px;
            padding: 10px;
            margin: 10px 0;
            font-size: 14px;
        }
        .tab {
            overflow: hidden;
            border: 1px solid #ccc;
            background-color: #f1f1f1;
            border-radius: 5px 5px 0 0;
        }
        .tab button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            transition: 0.3s;
            width: 50%;
            border-radius: 5px 5px 0 0;
        }
        .tab button:hover {
            background-color: #ddd;
        }
        .tab button.active {
            background-color: #007bff;
            color: white;
        }
        .tabcontent {
            display: none;
            padding: 20px;
            border: 1px solid #ccc;
            border-top: none;
            border-radius: 0 0 5px 5px;
        }
        .tabcontent.active {
            display: block;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>文本生成视频</h1>
        
        <div class="tab">
            <button class="tablinks active" onclick="openTab(event, 'single')">单个视频生成</button>
            <button class="tablinks" onclick="openTab(event, 'batch')">批量视频生成</button>
        </div>

        <div id="single" class="tabcontent active">
            <div class="note">
                <p><strong>功能说明：</strong></p>
                <ul>
                    <li>输入球赛信息和时间，系统将自动生成10秒的幽默剧情文本</li>
                    <li>然后根据剧情文本自动生成视频</li>
                    <li>视频风格为写实风格，使用真人演员，场景逼真</li>
                    <li>视频内容使用越南语，包含足球元素</li>
                    <li>视频分辨率为竖屏480p (480*832)</li>
                </ul>
            </div>
            
            <!-- 显示闪现消息 -->
            <div class="flash-messages">
                {% with messages = get_flashed_messages(with_categories=true) %}
                    {% if messages %}
                        {% for category, message in messages %}
                            <div class="flash-{{ category }}">{{ message }}</div>
                        {% endfor %}
                    {% endif %}
                {% endwith %}
            </div>
            
            <form id="t2vForm">
                <div class="form-group">
                    <label for="team_a">球队A名称:</label>
                    <input type="text" id="team_a" name="team_a" value="{{ cached_inputs.team_a or '' }}" placeholder="例如：巴西队" required>
                </div>
                
                <div class="form-group">
                    <label for="team_b">球队B名称:</label>
                    <input type="text" id="team_b" name="team_b" value="{{ cached_inputs.team_b or '' }}" placeholder="例如：德国队" required>
                </div>
                
                <div class="form-group">
                    <label for="match_time">比赛时间:</label>
                    <input type="text" id="match_time" name="match_time" value="{{ cached_inputs.match_time or '' }}" placeholder="例如：2025-10-11 15:00" required>
                </div>
                
                <div class="form-group">
                    <label for="match_name">赛事名称:</label>
                    <input type="text" id="match_name" name="match_name" value="{{ cached_inputs.match_name or '' }}" placeholder="例如：世界杯预选赛" required>
                </div>
                
                <div class="form-group">
                    <label for="output_dir">输出目录:</label>
                    <input type="text" id="output_dir" name="output_dir" value="{{ cached_inputs.output_dir or 'output/videos' }}" required>
                </div>
                
                <button type="submit">生成视频</button>
            </form>
        </div>

        <div id="batch" class="tabcontent">
            <div class="note">
                <p><strong>批量生成功能说明：</strong></p>
                <ul>
                    <li>Excel文件需要包含以下四个固定表头：球队A、球队B、比赛时间、赛事名称</li>
                    <li>可选添加"视频类型"列，值为"横屏"或"竖屏"，默认为"竖屏"</li>
                    <li>竖屏视频分辨率为480*832，横屏视频分辨率为832*480</li>
                    <li>系统将为Excel中的每一行数据生成一个视频</li>
                    <li>视频风格为写实风格，使用真人演员，场景逼真</li>
                    <li>视频内容使用越南语，包含足球元素</li>
                </ul>
            </div>
            
            <form id="t2vExcelForm">
                <div class="form-group">
                    <label for="excel_path">Excel文件路径:</label>
                    <input type="text" id="excel_path" name="excel_path" value="{{ cached_inputs.excel_path or '' }}" placeholder="例如：C:\data\matches.xlsx" required>
                </div>
                
                <div class="form-group">
                    <label for="excel_output_dir">输出目录:</label>
                    <input type="text" id="excel_output_dir" name="output_dir" value="{{ cached_inputs.output_dir or 'output/videos' }}" required>
                </div>
                
                <button type="submit">批量生成视频</button>
            </form>
        </div>
        
        <div id="result" class="result"></div>
        
        <div class="navigation">
            <a href="{{ url_for('index') }}" class="nav-link">← 返回主页</a>
        </div>
    </div>

    <script>
        function openTab(evt, tabName) {
            var i, tabcontent, tablinks;
            tabcontent = document.getElementsByClassName("tabcontent");
            for (i = 0; i < tabcontent.length; i++) {
                tabcontent[i].classList.remove("active");
            }
            tablinks = document.getElementsByClassName("tablinks");
            for (i = 0; i < tablinks.length; i++) {
                tablinks[i].classList.remove("active");
            }
            document.getElementById(tabName).classList.add("active");
            evt.currentTarget.classList.add("active");
        }

        document.getElementById('t2vForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const resultDiv = document.getElementById('result');
            
            // 显示处理中消息
            resultDiv.className = 'result';
            resultDiv.innerHTML = '<p>正在处理，请稍候...</p>';
            resultDiv.style.display = 'block';
            
            // 禁用提交按钮
            const submitButton = this.querySelector('button');
            submitButton.disabled = true;
            submitButton.textContent = '处理中...';
            
            // 发送请求
            fetch('/t2v-process', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 重定向到任务状态页面
                    window.location.href = '/t2v-task/' + data.task_id;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = '<p>错误: ' + data.error + '</p>';
                    resultDiv.style.display = 'block';
                    submitButton.disabled = false;
                    submitButton.textContent = '生成视频';
                }
            })
            .catch(error => {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = '<p>请求失败: ' + error.message + '</p>';
                resultDiv.style.display = 'block';
                submitButton.disabled = false;
                submitButton.textContent = '生成视频';
            });
        });

        document.getElementById('t2vExcelForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const resultDiv = document.getElementById('result');
            
            // 显示处理中消息
            resultDiv.className = 'result';
            resultDiv.innerHTML = '<p>正在处理，请稍候...</p>';
            resultDiv.style.display = 'block';
            
            // 禁用提交按钮
            const submitButton = this.querySelector('button');
            submitButton.disabled = true;
            submitButton.textContent = '处理中...';
            
            // 发送请求
            fetch('/t2v-excel-process', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 重定向到任务状态页面
                    window.location.href = '/t2v-task/' + data.task_id;
                } else {
                    resultDiv.className = 'result error';
                    resultDiv.innerHTML = '<p>错误: ' + data.error + '</p>';
                    resultDiv.style.display = 'block';
                    submitButton.disabled = false;
                    submitButton.textContent = '批量生成视频';
                }
            })
            .catch(error => {
                resultDiv.className = 'result error';
                resultDiv.innerHTML = '<p>请求失败: ' + error.message + '</p>';
                resultDiv.style.display = 'block';
                submitButton.disabled = false;
                submitButton.textContent = '批量生成视频';
            });
        });
    </script>
</body>
</html>